﻿## Example
#PoSH> Get-Content tab2.txt                                                                                              
#Name    Address Phone                                                                                                   
#Jack    5 XYZ Drive     555-4567                                                                                        
#Jill    7 XYZ Drive     555-6547                                                                                        
#Jake    9 XYZ Drive     555-9876                                                                                        
#PoSH> Import-TabDelimited tab2.txt                                                                                      
#                                                                                                                        
#Name                                    Address                                 Phone                                   
#----                                    -------                                 -----                                   
#Jack                                    5 XYZ Drive                             555-4567                                
#Jill                                    7 XYZ Drive                             555-6547                                
#Jake                                    9 XYZ Drive                             555-9876                                
#                                                                                                                        
#                                                                                                                        
#PoSH> Import-TabDelimited tab2.txt | Export-Csv csv2.csv -NoTypeInformation                                             
#PoSH> type csv2.csv                                                                                                     
#Name,Address,Phone                                                                                                      
#Jack,"5 XYZ Drive",555-4567                                                                                             
#Jill,"7 XYZ Drive",555-6547                                                                                             
#Jake,"9 XYZ Drive",555-9876                                                                                             
#PoSH> Import-Csv csv2.csv                                                                                               
#                                                                                                                        
#Name                                    Address                                 Phone                                   
#----                                    -------                                 -----                                   
#Jack                                    5 XYZ Drive                             555-4567                                
#Jill                                    7 XYZ Drive                             555-6547                                
#Jake                                    9 XYZ Drive                             555-9876 
##

function Import-TabDelimited ($Path) {
	$skiplines = 3  #Number of top lines to skip
  Get-Content $path |ForEach-Object {$header = $true; $line = 1}  {
  	if ($line -le $skiplines) {}
    elseif ($header){
      $h = $_.split("`t")
      $header = $false
    }
    Else {
      $r = new-object object
      $_.split("`t") |ForEach-Object {$i=0}{
        $r | add-Member -memberType noteProperty -name $h[$i] -value $_
        $i++
      }
      $r 
    }
	$line += 1
  }
}